#include "Operation.h"
#ifndef _TRANS
#include "Transformation.h"
#endif
#ifndef _STANDAR
#include "standar.h"
#endif

Action 
Operation::sum(Rectangular &num1In,  /*sumando1 - rectangular coordinates*/
               Rectangular &num2In,  /*sumando2 - rectangular coordinates*/ 
               Rectangular &resp     /*answer- rectangular coordinates*/)
{
   resp.setReal(num1In.getReal() + num2In.getReal());
   resp.setImaginary(num1In.getImaginary() + num2In.getImaginary());
   return (resp.getReal() == -1) ? FAIL : SUCCESS;
}

Action 
Operation::sum(Polar &num1In, /*sumando1 - Polar*/
               Polar &num2In, /*sumando2 - Polar*/
               Polar &resp    /*answer - Polar*/)
{
//temporal variables definition
//store complex number in a rectangular way
   Rectangular tempR1, tempR2;                           
//Object to make a transformation
   Transformation *trans = new Transformation;        
//ALGORITHM
//transformation 
   trans->polarToRectangular(num1In,tempR1);          
   trans->polarToRectangular(num2In,tempR2);
//addition real part
   tempR1.setReal(tempR1.getReal()+tempR2.getReal()); 
//addition imaginary part
   tempR1.setImaginary(tempR1.getImaginary()+
                      tempR2.getImaginary());        
//re-transformation 
   trans->rectangularToPolar(tempR1,resp);           
   return (resp.getMagnitude() == -1) ? FAIL : SUCCESS;
}

Action 
Operation::multiplication(Rectangular *num1In,  /*multiplicando1 - Rectangular*/ 
                          Rectangular *num2In,  /*multiplicando2 - Rectangular*/  
                          Rectangular *resp     /*answer - Rectangular*/ )
{
//temporal variables definition 
   cout << "To make the transformation is necessary to create two temp objects" 
     << endl;
   Polar tempP1, tempP2;
   Transformation trans;
   float tempMag, tempAng;
//algorithm
//transformation to Polar
   trans.rectangularToPolar(*num1In,tempP1);                  
   trans.rectangularToPolar(*num2In,tempP2);             
//multiplication magnitude
   tempMag = (tempP1.getMagnitude())*(tempP2.getMagnitude());   
//addition angles
   tempAng = tempP1.getAngle()+tempP2.getAngle();           
//conformation a Polar number
   tempP1.setMagnitude(tempMag);                            
   tempP1.setAngle(tempAng);
//transformation to Rectangular 
   trans.polarToRectangular(tempP1,*resp);                
   return (resp->getReal() == -1) ? FAIL : SUCCESS;
}

Action 
Operation::multiplication(Polar *num1In,  /*multiplicando1 - Polar*/
                          Polar *num2In,  /*multiplicando1 - Polar*/
                          Polar *resp     /*answer* - Polar*/)
{
//magnitude multiplication
   (*resp).setMagnitude((*num1In).getMagnitude()*  (*num2In).getMagnitude()); 
//Angle addition
   resp->setAngle(num1In->getAngle() + num2In->getAngle());                   
   return (resp->getMagnitude() == -1) ? FAIL : SUCCESS;
}

/* Abbreviation Table
* tempP1 == temporal Polar 1
* tempP2 == temporal Polar 2
* tempMag== temporal Magnitud 
* tempAng== temporal Angle
* trnas  == transformator (Object)
* num1In == number 1 to In
* num2In == number 2 to In
* resp == respuesta (answer)
*/
